import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from 'vue';
import {Avatar, Switch, Tag} from 'ant-design-vue';
import {useMessage} from "/@/hooks/web/useMessage";
import {setUserStatus} from './api';

export const columns: BasicColumn[] = [
  {
    title: '用户编号',
    dataIndex: 'userNo',
    width: 100,
  },
  {
    title: '头像',
    dataIndex: 'avatar',
    width: 120,
    customRender: ({record}) => {
      const avatar = record.avatar;
      return h(Avatar, {src: avatar});
    }
  },
  {
    title: '用户名',
    dataIndex: 'userName',
    width: 150,
  },
  {
    title: '昵称',
    dataIndex: 'nickName',
    width: 150,
  },
  {
    title: '性别',
    dataIndex: 'sex',
    width: 100,
    customRender: ({record}) => {
      const sex = record.sex;
      const color = sex == 1 ? 'blue' : 'green';
      const text = sex == 1 ? '男' : '女';
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    customRender: ({record}) => {
      if (!Reflect.has(record, 'pendingStatus')) {
        record.pendingStatus = false;
      }
      return h(Switch, {
        checked: record.status === 1,
        checkedChildren: '已启用',
        unCheckedChildren: '已禁用',
        loading: record.pendingStatus,
        onChange() {
          record.pendingStatus = false;
          const {createMessage} = useMessage();
          setUserStatus(record.userId).then((data) => {
            record.status = data;
            createMessage.success(`已成功修改用户状态`);
          }).catch((data) => {
            console.info('catch', data)
            createMessage.error('修改用户状态失败');
          }).finally(() => {
            record.pendingStatus = false;
          });
        },
      });
    },
  },
  {
    title: '所属公众号',
    dataIndex: 'weChatName',
    width: 120,
  },
  {
    title: 'openId',
    dataIndex: 'openId',
    width: 120,
  },
  {
    title: '注册方式',
    dataIndex: 'registerWayLabel',
    width: 150,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 150,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'employeeName',
    label: '会员姓名/手机号',
    component: 'Input',
    colProps: {span: 4}
  },
  {
    field: 'airportId',
    label: '开卡地',
    component: 'Input',
    colProps: {span: 4}
  }, {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: {span: 5},
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: {span: 5},
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  }
];

export const formSchema: FormSchema[] = [
  {
    label: '用户编号',
    field: 'userNo',
    component: 'Input',
    required: true,
  },
  {
    label: '用户名',
    field: 'userName',
    component: 'Input',
    required: true,
  },
  {
    label: '昵称',
    field: 'nickName',
    component: 'Input',
    required: true,
  },
  {
    label: '支付密码',
    field: 'payPwd',
    component: 'Input',
    required: true,
  },
  {
    label: '头像',
    field: 'avatar',
    component: 'Input',
    required: true,
  },
  {
    label: '性别 0=未知 1=男 2=女',
    field: 'sex',
    component: 'Input',
    required: true,
  },
  {
    label: '个人封面',
    field: 'frontCoverImage',
    component: 'Input',
    required: true,
  },
  {
    label: '区',
    field: 'areaId',
    component: 'Input',
    required: true,
  },
  {
    label: '市',
    field: 'cityId',
    component: 'Input',
    required: true,
  },
  {
    label: '省',
    field: 'proId',
    component: 'Input',
    required: true,
  },
  {
    label: '区域全称',
    field: 'areaName',
    component: 'Input',
    required: true,
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    required: true,
  },
  {
    label: '学校是否认证',
    field: 'schoolAuth',
    component: 'Input',
    required: true,
  },
  {
    label: '手机号',
    field: 'mobile',
    component: 'Input',
    required: true,
  },
  {
    label: '国际区号',
    field: 'areaCode',
    component: 'Input',
    required: true,
  },
  {
    label: '用户类型',
    field: 'userType',
    component: 'Input',
    required: true,
  },
  {
    label: '生日',
    field: 'birthday',
    component: 'Input',
    required: true,
  },
  {
    label: '主角色',
    field: 'roleId',
    component: 'Input',
    required: true,
  },
  {
    label: '职务',
    field: 'position',
    component: 'Input',
    required: true,
  },
  {
    label: '职务ID',
    field: 'positionId',
    component: 'Input',
    required: true,
  },
  {
    label: '部门',
    field: 'deptId',
    component: 'Input',
    required: true,
  },
  {
    label: '企业ID',
    field: 'companyId',
    component: 'Input',
    required: true,
  },
  {
    label: '学校ID',
    field: 'schoolId',
    component: 'Input',
    required: true,
  },
  {
    label: '注册IP',
    field: 'registerIp',
    component: 'Input',
    required: true,
  },
  {
    label: '状态:0-禁用 1-启用 2-锁定',
    field: 'status',
    component: 'Input',
    required: true,
  },
  {
    label: '微信号',
    field: 'wechatNo',
    component: 'Input',
    required: true,
  },
  {
    label: '邀请人ID',
    field: 'inviterId',
    component: 'Input',
    required: true,
  },
  {
    label: '邀请码',
    field: 'shareCode',
    component: 'Input',
    required: true,
  },
  {
    label: '用户token',
    field: 'userToken',
    component: 'Input',
    required: true,
  },
  {
    label: '个人简介',
    field: 'personProfile',
    component: 'Input',
    required: true,
  },
  {
    label: '签名',
    field: 'motto',
    component: 'Input',
    required: true,
  },
  {
    label: '标签',
    field: 'tags',
    component: 'Input',
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
    required: true,
  },
  {
    label: '业务数量',
    field: 'busNum',
    component: 'Input',
    required: true,
  },
  {
    label: '推送系统通知',
    field: 'pushSysMsg',
    component: 'Input',
    required: true,
  },
  {
    label: '推送订单通知',
    field: 'pushOrderMsg',
    component: 'Input',
    required: true,
  },
  {
    label: '推送其他通知',
    field: 'pushOtherMsg',
    component: 'Input',
    required: true,
  },
  {
    label: '所属公众号Id',
    field: 'weChatId',
    component: 'Input',
    required: true,
  },
  {
    label: '用户openId',
    field: 'openId',
    component: 'Input',
    required: true,
  },
  {
    label: '完善资料Id',
    field: 'privateDataId',
    component: 'Input',
    required: true,
  },
  {
    label: '注册方式',
    field: 'registerWay',
    component: 'Input',
    required: true,
  },
  {
    label: '创建时间',
    field: 'createTime',
    component: 'Input',
    required: true,
  },
  {
    label: '更新时间',
    field: 'updateTime',
    component: 'Input',
    required: true,
  },
];
